package com.cy.aircompressor.main.ui.onlinemonitor.provider;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;

import androidx.annotation.NonNull;

import com.cy.aircompressor.config.AirConfig;
import com.cy.aircompressor.databinding.ItemCompressorLayoutBinding;
import com.cy.aircompressor.databinding.ItemSensorDataLayoutBinding;
import com.cy.aircompressor.entity.compressor.Compressor;
import com.cy.aircompressor.entity.select.SelectDict;
import com.cy.aircompressor.entity.sensor.SensorItemData;
import com.cy.aircompressor.entity.sensor.SensorProvider;
import com.cy.aircompressor.main.ui.Infoover.view.StageCylinderView;
import com.drug.lib.view.recycptr.ItemViewBinder;
import com.net.model.base.BaseBindViewHolder;

import java.util.List;

public class SensorItemProvider extends ItemViewBinder<SensorProvider, SensorItemProvider.ViewHolder> {
    Context mContext;

    public SensorItemProvider(Context mContext) {
        this.mContext = mContext;
    }

    @NonNull
    @Override
    protected SensorItemProvider.ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        return new ViewHolder(ItemSensorDataLayoutBinding.inflate(inflater, parent, false));
    }

    @Override
    protected void onBindViewHolder(@NonNull SensorItemProvider.ViewHolder holder, @NonNull SensorProvider entity) {
        holder.mBinding.partsName.setText(entity.getSelectDict().getLabel());
        if (TextUtils.equals(entity.getSelectDict().getValue(), "body")) {
            holder.mBinding.partsBodyView.setVisibility(View.VISIBLE);
            holder.mBinding.partsPressureView.setVisibility(View.GONE);
            holder.mBinding.partsTemperatureView.setVisibility(View.GONE);
            if (entity.getWaterItemData() != null) {
                holder.mBinding.pressureWater.setText(entity.getWaterItemData().getV());
            } else {
                holder.mBinding.pressureWater.setText("--");
            }
            if (entity.getOilItemData() != null) {
                holder.mBinding.pressureOil.setText(entity.getOilItemData().getV());
            } else {
                holder.mBinding.pressureOil.setText("--");
            }

            if (entity.getVibration1ItemData() != null) {
                holder.mBinding.bodyX.setText(String.valueOf(entity.getVibration1ItemData().getXspeed()));
                holder.mBinding.bodyY.setText(String.valueOf(entity.getVibration1ItemData().getYspeed()));
                holder.mBinding.bodyZ.setText(String.valueOf(entity.getVibration1ItemData().getZspeed()));

                holder.mBinding.bodyXrms.setText(String.valueOf(entity.getVibration1ItemData().getXrms()));
                holder.mBinding.bodyYrms.setText(String.valueOf(entity.getVibration1ItemData().getYrms()));
                holder.mBinding.bodyZrms.setText(String.valueOf(entity.getVibration1ItemData().getZrms()));
            } else {
                holder.mBinding.bodyX.setText("--");
                holder.mBinding.bodyY.setText("--");
                holder.mBinding.bodyZ.setText("--");
                holder.mBinding.bodyXrms.setText("--");
                holder.mBinding.bodyYrms.setText("--");
                holder.mBinding.bodyZrms.setText("--");
            }
            if (entity.getVibration2ItemData() != null) {
                holder.mBinding.firstX.setText(String.valueOf(entity.getVibration2ItemData().getXspeed()));
                holder.mBinding.firstY.setText(String.valueOf(entity.getVibration2ItemData().getYspeed()));
                holder.mBinding.firstZ.setText(String.valueOf(entity.getVibration2ItemData().getZspeed()));

                holder.mBinding.firstXrms.setText(String.valueOf(entity.getVibration2ItemData().getXrms()));
                holder.mBinding.firstYrms.setText(String.valueOf(entity.getVibration2ItemData().getYrms()));
                holder.mBinding.firstZrms.setText(String.valueOf(entity.getVibration2ItemData().getZrms()));
            } else {
                holder.mBinding.firstX.setText("--");
                holder.mBinding.firstY.setText("--");
                holder.mBinding.firstZ.setText("--");
                holder.mBinding.firstXrms.setText("--");
                holder.mBinding.firstYrms.setText("--");
                holder.mBinding.firstZrms.setText("--");
            }
            if (entity.getVibration3ItemData() != null) {
                holder.mBinding.secondX.setText(String.valueOf(entity.getVibration3ItemData().getXspeed()));
                holder.mBinding.secondY.setText(String.valueOf(entity.getVibration3ItemData().getYspeed()));
                holder.mBinding.secondZ.setText(String.valueOf(entity.getVibration3ItemData().getZspeed()));

                holder.mBinding.secondXrms.setText(String.valueOf(entity.getVibration3ItemData().getXrms()));
                holder.mBinding.secondYrms.setText(String.valueOf(entity.getVibration3ItemData().getYrms()));
                holder.mBinding.secondZrms.setText(String.valueOf(entity.getVibration3ItemData().getZrms()));
            } else {
                holder.mBinding.secondX.setText("--");
                holder.mBinding.secondY.setText("--");
                holder.mBinding.secondZ.setText("--");
                holder.mBinding.secondXrms.setText("--");
                holder.mBinding.secondYrms.setText("--");
                holder.mBinding.secondZrms.setText("--");
            }


        } else {
            holder.mBinding.partsBodyView.setVisibility(View.GONE);
            holder.mBinding.partsPressureView.setVisibility(View.VISIBLE);
            holder.mBinding.partsTemperatureView.setVisibility(View.VISIBLE);
            if (entity.getPressureItemData() != null) {
                holder.mBinding.textValue2.setText(entity.getPressureItemData().getV());
            } else {
                holder.mBinding.textValue2.setText("--");
            }
            if (entity.getTemperatureItemData() != null) {
                holder.mBinding.textValue.setText(entity.getTemperatureItemData().getV());
            } else {
                holder.mBinding.textValue.setText("--");
            }
        }

    }


    public class ViewHolder extends BaseBindViewHolder<ItemSensorDataLayoutBinding> {

        protected ViewHolder(ItemSensorDataLayoutBinding itemView) {
            super(itemView);
        }
    }
}
